-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update TIME and DATE functions #134
Update TIME and DATE functions #134
Conversation
…y to parse time out of datetime or date out of datetime. Signed-off-by: MitchellGale-BitQuill <[email protected]>
Codecov Report
@@ Coverage Diff @@
## Integ-updateDateFunction #134 +/- ##
===========================================================
Coverage ? 95.10%
Complexity ? 3073
===========================================================
Files ? 303
Lines ? 8254
Branches ? 610
===========================================================
Hits ? 7850
Misses ? 350
Partials ? 54
Flags with carried forward coverage won't be shown. Click here to find out more. 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mysql> select DATE(TIME('13:49:00')), TIME(DATE('2020-08-26'));
+------------------------+--------------------------+
| DATE(TIME('13:49:00')) | TIME(DATE('2020-08-26')) |
+------------------------+--------------------------+
| 2022-10-13 | 00:00:00 |
+------------------------+--------------------------+
1 row in set (0.00 sec)
opensearchsql> select DATE(TIME('13:49:00')), TIME(DATE('2020-08-26'));
{'reason': 'Invalid SQL query', 'details': 'date function expected {[STRING],[DATE],[DATETIME],[TIMESTAMP]}, but get [TIME]', 'type': 'ExpressionEvaluationException'}
I think you need to apply/cherry-pick 40ffca2 into your branch to fix that. |
…orresponding tests. Signed-off-by: Yury-Fridlyand <[email protected]>
…ction.java Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
@@ -651,7 +652,11 @@ private ExprValue exprConvertTZ(ExprValue startingDateTime, ExprValue fromTz, Ex | |||
*/ | |||
private ExprValue exprDate(ExprValue exprValue) { | |||
if (exprValue instanceof ExprStringValue) { | |||
return new ExprDateValue(exprValue.stringValue()); | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to remove the if
statement and get the same result. The try...catch
will cover both cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need it because it can be a stringValue or a dateValue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a case where an ExprStringValue doesn't have a stringValue()?
@@ -944,6 +949,7 @@ private ExprValue exprSubDateInterval(ExprValue date, ExprValue expr) { | |||
*/ | |||
private ExprValue exprTime(ExprValue exprValue) { | |||
if (exprValue instanceof ExprStringValue) { | |||
//try catch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo?
@@ -240,6 +240,11 @@ public void date() { | |||
assertEquals(DATE, expr.type()); | |||
assertEquals(new ExprDateValue("2020-08-17"), eval(expr)); | |||
assertEquals("date(DATE '2020-08-17')", expr.toString()); | |||
|
|||
expr = dsl.date(DSL.literal(new ExprDateValue("2020-08-17 12:12:00"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should test with nano seconds too
@@ -795,6 +800,11 @@ public void time() { | |||
assertEquals(TIME, expr.type()); | |||
assertEquals(new ExprTimeValue("01:01:01"), eval(expr)); | |||
assertEquals("time(TIME '01:01:01')", expr.toString()); | |||
|
|||
expr = dsl.time(DSL.literal(new ExprTimeValue("2020-01-02 01:01:01"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should test with nano seconds too (separately)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added case for times < 1.0 seconds. 2016222
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
|
||
public static final DateTimeFormatter TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL = | ||
new DateTimeFormatterBuilder() | ||
.appendPattern("[uuuu-MM-dd HH:mm:ss][HH:mm:ss]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have tests for both patterns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All patterns should have coverage
core/src/main/java/org/opensearch/sql/utils/DateTimeFormatters.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java
Outdated
Show resolved
Hide resolved
Signed-off-by: MitchellGale-BitQuill <[email protected]>
…E functions. Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
@@ -650,8 +652,15 @@ private ExprValue exprConvertTZ(ExprValue startingDateTime, ExprValue fromTz, Ex | |||
* @return ExprValue. | |||
*/ | |||
private ExprValue exprDate(ExprValue exprValue) { | |||
if (exprValue.type() == TIME) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use a switch on type() here. For TIME, STRING, DATE, and TIMESTAMP?
if (exprValue instanceof ExprStringValue) { | ||
return new ExprTimeValue(exprValue.stringValue()); | ||
try { | ||
return new ExprTimeValue(exprValue.stringValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use a switch on type() here. For TIME, STRING, DATE, and TIMESTAMP?
@MitchellGale-BitQuill, |
…cal time now. Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
@Yury-Fridlyand Added support for HH:mm in 61289bb. |
Removed blocking component. It can be fixed in a later PR. |
core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java
Outdated
Show resolved
Hide resolved
Signed-off-by: MitchellGale-BitQuill <[email protected]>
@@ -67,7 +69,7 @@ public LocalDateTime datetimeValue() { | |||
|
|||
@Override | |||
public Instant timestampValue() { | |||
return ZonedDateTime.of(date, timeValue(), ZoneId.systemDefault()).toInstant(); | |||
return ZonedDateTime.of(date, timeValue(), ZoneId.of("UTC")).toInstant(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last minor change - you need to revert this as well ... or ... update test to use UTC
too.
Signed-off-by: MitchellGale-BitQuill <[email protected]>
…prDateValue.java for timestampValue to use systemDefault instead of UTC time. Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: Andriy Redko <[email protected]>
Description
Add option to accept datetime like string in both TIME and DATE (eg. accept "1999-01-02 12:12:12" for both TIME and DATE.
Strict check on date for testing for valid dates (eg. Don't accept Feb 30th as a valid date)
Issues Resolved
[List any issues this PR will resolve]
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.